var $baseUrl = {
    fileServiceUrl: window.g.fileServiceUrl,
    baseUrl: window.g.baseUrl,
    jumpUrl: window.g.baseUrl
}

function ajax(method, url, data, callback) {
    var xhr = new XMLHttpRequest();
    xhr.open(method, $baseUrl.baseUrl + url, true);
    xhr.onreadystatechange = function () {
        if (xhr.readyState === 4 && xhr.status === 200) {
            callback(JSON.parse(xhr.responseText));
        }
    };
    if (method === 'POST') {
        xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
    }
    xhr.send(data);
}
function xhrPromise(method,url) {  
    return new Promise((resolve, reject) => {  
      var xhr = new XMLHttpRequest();  
      xhr.open(method, $baseUrl.baseUrl + url, true);
      xhr.onload = () => {  
        if (xhr.readyState === 4 && xhr.status === 200) {  
          resolve(JSON.parse(xhr.responseText));  
        } else {  
          reject(new Error('Request failed with status: ' + xhr));  
        }  
      };  
      xhr.onerror = () => reject(new Error('Network error'));  
      xhr.send();  
    });  
  }  
    

// // 使用方法示例
// ajax('GET', 'https://api.example.com/data', null, function (response) {
//     //console.log(response);
// });

// ajax('POST', 'https://api.example.com/data', 'key1=value1&key2=value2', function (response) {
//     //console.log(response);
// });
function formatTime() {
    // 创建一个Date对象，表示当前时间  
    const now = new Date();
    // 获取当前年份  
    const year = now.getFullYear();
    // 获取当前月份（注意JavaScript中月份是从0开始的，所以需要加1）  
    const month = now.getMonth() + 1; // January is 0, February is 1, and so on  
    // 获取当前日期（1-31）  
    const date = now.getDate();
    // 获取当前小时（0-23）  
    const hours = now.getHours();
    // 获取当前分钟（0-59）  
    const minutes = now.getMinutes();
    // 获取当前秒数（0-59）  
    const seconds = now.getSeconds();
    const weekdays = ["星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"];
    // 为了保证显示格式统一，当值小于10时前面补0  
    function padWithZeros(value, width) {
        let result = "000000000" + value;
        return result.substr(result.length - width);
    }
    const weekday = weekdays[now.getDay()]
    const formattedDate = `${year}-${padWithZeros(month, 2)}-${padWithZeros(date, 2)} ${padWithZeros(hours, 2)}:${padWithZeros(minutes, 2)}:${padWithZeros(seconds, 2)}  ${weekday}`;
    return formattedDate
}